using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AppManagement.Repositories
{
	#region using
	using AppManagement.Models;
	#endregion
	public class PhieuKhamRepository
	{
		public static List<PhieuKham> SelectAll()
		{
			return DataContext.Instance.PhieuKhams.ToList();
		}

		public static PhieuKham SelectByID(string mapk)
		{
			return DataContext.Instance.PhieuKhams.FirstOrDefault(item => item.MaPK == mapk );
		}

		public static bool Insert(PhieuKham obj)
		{
			try
			{
				DataContext.Instance.PhieuKhams.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(string mapk)
		{
			try
			{
				var delitem = DataContext.Instance.PhieuKhams.FirstOrDefault(item => item.MaPK == mapk );
				DataContext.Instance.PhieuKhams.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<PhieuKham> RetrieveByID(string mapk)
		{
			return (from item in DataContext.Instance.PhieuKhams where  item.MaPK == mapk  select item).ToList();
		}

		public static List<PhieuKham> SelectByMaBN(string mabn)
		{
			var lstItem = (from item in DataContext.Instance.PhieuKhams where item.MaBN == mabn select item).ToList();
			return lstItem;
		}

	}
}